#include "NodeScript.h"
#include "T_Node.h"
#include "clazz.h"

static int node_setPosition(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	Gdiplus::PointF *pnt = (Gdiplus::PointF *)ModuleCheck(L,2,"Point");
	node->setPosition(*pnt);
	return 0;
}

static int node_getPosition(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	ModuleInstance(L,new Gdiplus::PointF(node->getPosition()),"Point",true);
	return 1;
}

static int node_getWorldBounds(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	ModuleInstance(L,new Gdiplus::RectF(node->getWorldBounds()),"Rect",true);
	return 1;
}

static int node_getWorldPosition(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	ModuleInstance(L,new Gdiplus::PointF(node->getWorldPosition()),"Point",true);
	return 1;
}

static int node_getBaseZero(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	ModuleInstance(L,new Gdiplus::PointF(node->getBaseZero()),"Point",true);
	return 1;
}

static int node_updatePosition(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	node->updatePosition();
	return 0;
}

static int node_setVisible(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	node->setVisible((bool)lua_toboolean(L,2));
	return 0;
}

static int node_isVisible(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	lua_pushboolean(L,node->isVisible());
	return 1;
}

static int node_getSize(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	ModuleInstance(L,new Gdiplus::SizeF(node->getSize()),"Size",true);
	return 1;
}

static int node_setSize(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	Gdiplus::SizeF *sz = (Gdiplus::SizeF *)ModuleCheck(L,2,"Size");
	node->setSize(*sz);
	return 0;
}

static int node_updateSize(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	node->updateSize();
	return 0;
}

static int node_(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	return 1;
}

static int node_getZOrder(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	lua_pushinteger(L,node->getZOrder());
	return 1;
}

static int node_setLocalZOrder(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	node->setLocalZOrder((int)luaL_checkinteger(L,2));
	return 0;
}

static int node_updateZOrder(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	node->updateZOrder();
	return 0;
}

static int node_getLocalZOrder(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	lua_pushinteger(L,node->getLocalZOrder());
	return 1;
}

static int node_setCascadeScaleEnabled(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	node->setCascadeScaleEnabled((bool)lua_toboolean(L,2));
	return 0;
}

static int node_setScaleX(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	node->setScaleX((float)luaL_checknumber(L,2));
	return 0;
}

static int node_setScaleY(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	node->setScaleY((float)luaL_checknumber(L,2));
	return 0;
}

static int node_getScaleX(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	lua_pushnumber(L,node->getScaleX());
	return 1;
}

static int node_getScaleY(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	lua_pushnumber(L,node->getScaleY());
	return 1;
}

static int node_setScale(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	node->setScale((float)luaL_checknumber(L,2));
	return 0;
}

static int node_updateScale(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	node->updateScale();
	return 0;
}

static int node_setTag(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	node->setTag((int)luaL_checkinteger(L,2));
	return 0;
}

static int node_getTag(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	lua_pushinteger(L,node->getTag());
	return 1;
}

static int node_getChildByTag(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	T_Node *child = node->getChildByTag((int)luaL_checkinteger(L,2));
	ModuleInstance(L,child,"Node");
	return 1;
}

static int node_setAlpha(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	node->setAlpha((short)luaL_checkinteger(L,2));
	return 0;
}

static int node_getAlpha(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	lua_pushinteger(L,node->getAlpha());
	return 1;
}

static int node_setTouchEnabled(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	node->setTouchEnabled((bool)lua_toboolean(L,2));
	return 0;
}

static int node_isTouchEnabled(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	lua_pushboolean(L,node->isTouchEnabled());
	return 1;
}

static int node_runAction(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	T_Action *action = (T_Action *)ModuleCheck(L,2,"Action");
	node->runAction(action);
	return 0;
}

static int node_addChild(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	T_Node *child = (T_Node *)ModuleCheck(L,2,"Node");
	lua_pushboolean(L,node->addChild(child));
	return 1;
}

static int node_getParent(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	ModuleInstance(L,node->getParent(),"Node");
	return 1;
}

static int node_removeChild(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	T_Node *child = (T_Node *)ModuleCheck(L,2,"Node");
	node->removeChild(child);
	return 0;
}

static int node_removeAllChildren(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	node->removeAllChildren();
	return 0;
}

static int node_getScene(lua_State *L){
	T_Node *node = (T_Node *)ModuleCheck(L,1,"Node");
	ModuleInstance(L,node->getScene(),"Scene");
	return 1;
}

int lua_opennode(lua_State *L){
	BeginModule(L,"Node");
	NormalFunction(L,"setPosition",node_setPosition);
	NormalFunction(L,"getPosition",node_getPosition);
	NormalFunction(L,"getWorldBounds",node_getWorldBounds);
	NormalFunction(L,"getWorldPosition",node_getWorldPosition);
	NormalFunction(L,"getBaseZero",node_getBaseZero);
	NormalFunction(L,"setVisible",node_setVisible);
	NormalFunction(L,"isVisible",node_isVisible);
	NormalFunction(L,"setSize",node_setSize);
	NormalFunction(L,"getSize",node_getSize);
	NormalFunction(L,"updateSize",node_updateSize);
	NormalFunction(L,"getZOrder",node_getZOrder);
	NormalFunction(L,"setLocalZOrder",node_setLocalZOrder);
	NormalFunction(L,"getLocalZOrder",node_getLocalZOrder);
	NormalFunction(L,"setCascadeScaleEnabled",node_setCascadeScaleEnabled);
	NormalFunction(L,"setScaleX",node_setScaleX);
	NormalFunction(L,"setScaleY",node_setScaleY);
	NormalFunction(L,"getScaleX",node_getScaleX);
	NormalFunction(L,"getScaleY",node_getScaleY);
	NormalFunction(L,"setScale",node_setScale);
	NormalFunction(L,"setTag",node_setTag);
	NormalFunction(L,"getTag",node_getTag);
	NormalFunction(L,"getChildByTag",node_getChildByTag);
	NormalFunction(L,"setAlpha",node_setAlpha);
	NormalFunction(L,"getAlpha",node_getAlpha);
	NormalFunction(L,"setTouchEnabled",node_setTouchEnabled);
	NormalFunction(L,"isTouchEnabled",node_isTouchEnabled);
	NormalFunction(L,"runAction",node_runAction);
	NormalFunction(L,"addChild",node_addChild);
	NormalFunction(L,"getParent",node_getParent);
	NormalFunction(L,"removeChild",node_removeChild);
	NormalFunction(L,"removeAllChildren",node_removeAllChildren);
	NormalFunction(L,"getScene",node_getScene);
	EndModule(L);
	return 0;
}


int lua_closenode(lua_State *L){
	lua_pushnil(L);
	lua_setglobal(L,"Node");
	return 0;
}